package com.yanqu.road.server.gameplayer.module.activity.drawPictures;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.drawPictures.*;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.log.LogDrawPictures;
import com.yanqu.road.entity.log.LogDrawPicturesPray;
import com.yanqu.road.entity.task.args.DrawPicturesActivityCombArgs;
import com.yanqu.road.logic.bussiness.player.activity.UserDrawPicturesBusiness;
import com.yanqu.road.pb.drawPicturesActivity.DrawPicturesProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.drawPictures.DrawPicturesActivityMgr;
import com.yanqu.road.server.manger.config.GoodsMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.pb.DrawPicturesActivityPb;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DrawPicturesActivityModule extends GeneralModule {

    //activityId - data
    private Map<Integer, UserDrawPicturesActivityData> userDrawPicturesActivityDataMap; //玩家活动数据
    //activityId - picturesId
    private Map<Integer, Map<Integer, UserPictures>> userPicturesMap; //玩家年画数据
    //activityId - combId
    private Map<Integer, Map<Integer, UserPicturesComb>> userPicturesCombMap; //玩家祈福数据

    public DrawPicturesActivityModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        List<Integer> activityIdList = NormalActivityMgr.getOpenActivityIdList(eActivityType.DrawPicturesActivity.getValue());
        if (activityIdList.size() == 0) {
            userDrawPicturesActivityDataMap = new ConcurrentHashMap<>();
            userPicturesMap = new ConcurrentHashMap<>();
            userPicturesCombMap = new ConcurrentHashMap<>();
        } else {
            userDrawPicturesActivityDataMap = UserDrawPicturesBusiness.getDrawPicturesUserActivityData(activityIdList, getUserId());
            userPicturesMap = UserDrawPicturesBusiness.getDrawPicturesUserPicturesData(activityIdList, getUserId());
            userPicturesCombMap = UserDrawPicturesBusiness.getDrawPicturesUserPicturesCombData(activityIdList, getUserId());
        }

        return true;
    }

    public void syncActivity() {
        if (SystemOpenMgr.systemOpen(player, eSystemId.DrawPicturesActivity.getValue())) {
            syncUserDataList();
            syncActivityConfigList();
        //    autoUseActivityGoods(NormalActivityMgr.getOpenActivityInfoList(eActivityType.DrawPicturesActivity.getValue()));
           // autoConsumePictures(NormalActivityMgr.getOpenActivityInfoList(eActivityType.DrawPicturesActivity.getValue()));
        }
    }

    private void syncActivityConfigList() {
        List<Integer> activityIdList = NormalActivityMgr.getOpenActivityIdList(eActivityType.DrawPicturesActivity.getValue());
        if (activityIdList.size() > 0) {
            DrawPicturesProto.DrawPictureConfigSyncMsg.Builder syncMsg = DrawPicturesProto.DrawPictureConfigSyncMsg.newBuilder();
            for (Integer activityId : activityIdList) {
                Map<Integer, PicturesWeight> pictureWeightMap = DrawPicturesActivityMgr.getPictureWeightMap(activityId);
                Map<Integer, PicturesComb> picturesCombMap = DrawPicturesActivityMgr.getPicturesCombMap(activityId);
                syncMsg.addConfig(DrawPicturesActivityPb.parseConfigTemp(activityId, pictureWeightMap, picturesCombMap, player.getLanguage()));
            }
            player.sendPacket(ClientProtocol.U_ACTIVITY_DRAW_PICTURES_CONFIG_DATA_SYNC, syncMsg);
        }
    }

    private void autoUseActivityGoods(List<ActivityInfo> openActivityInfoList) {
        if (null != openActivityInfoList && openActivityInfoList.size() > 0) {
            for (ActivityInfo activityInfo : openActivityInfoList) {
              //  autoUseActivityGoods(activityInfo);
            }
        }
    }

    public void autoUseActivityGoods(ActivityInfo activityInfo) {
        if (ActivityMgr.activityInShowPeriod(activityInfo) || ActivityMgr.activityInRewardPeriod(activityInfo)) {//在展示期或者领奖期
            int activityConsumeId = DrawPicturesActivityMgr.getActivityConsumeId(activityInfo);
         //   player.getModule(BagModule.class).removeActivityBagItemToScore(activityInfo, DrawPicturesActivityMgr.getActivityScoreId(activityInfo), activityConsumeId, 0, MailManager.ACTIVITY_GOODS_AUTO_CONSUME_TITLE, MailManager.ACTIVITY_GOODS_AUTO_CONSUME_CONTENT);
        }
    }

    private void autoConsumePictures(List<ActivityInfo> openActivityInfoList) {
        if (null != openActivityInfoList && openActivityInfoList.size() > 0) {
            for (ActivityInfo activityInfo : openActivityInfoList) {
                autoConsumePictures(activityInfo);
            }
        }
    }

    private void autoConsumePictures(ActivityInfo activityInfo) {
        synchronized (this) {
            if (ActivityMgr.activityInShowPeriod(activityInfo) || ActivityMgr.activityInRewardPeriod(activityInfo)) {//在展示期或者领奖期
                Map<Integer, UserPictures> picturesMap = userPicturesMap.get(activityInfo.getActivityId());
                if (picturesMap != null) {
                    int blueCount = 0;
                    int purpleCount = 0;
                    int orangeCount = 0;
                    int totalIntegral = 0;
                    String[] strings = DrawPicturesActivityMgr.getPicturesDesc(activityInfo).split("\\|");
                    String blueName = ServerLanguageMgr.getContent(strings[0], player.getLanguage());
                    String purpleName = ServerLanguageMgr.getContent(strings[1], player.getLanguage());
                    String orangeName = ServerLanguageMgr.getContent(strings[2], player.getLanguage());
                    GoodsInfo goodsInfo = GoodsMgr.getGoodsById(DrawPicturesActivityMgr.getActivityScoreId(activityInfo));
                    if(null == goodsInfo){
                        log.error("remove  activity goods to score error,goods no found,goodsId:{}", DrawPicturesActivityMgr.getActivityScoreId(activityInfo));
                        return;
                    }
                    String goodsName = ServerLanguageMgr.getContent(goodsInfo.getGoodsName(), player.getLanguage());

                    for (UserPictures pictures : picturesMap.values()) {
                        PicturesWeight picturesConfig = DrawPicturesActivityMgr.getPictureWeightMap(activityInfo.getActivityId()).get(pictures.getPicturesId());
                        int preCount = pictures.getNum();
                        if (picturesConfig != null) {
                            if (picturesConfig.getQuality() == 2) {
                                blueCount += pictures.getNum();
                            } else if (picturesConfig.getQuality() == 3) {
                                purpleCount += pictures.getNum();
                            } else if (picturesConfig.getQuality() == 4) {
                                orangeCount += pictures.getNum();
                            }
                            totalIntegral += (picturesConfig.getTransformIntegral() * pictures.getNum());
                        }
                        pictures.setNum(0);
//                        LogMgr.addLogDrawPictures(new LogDrawPictures(getUserId(), activityInfo.getActivityId(),  pictures.getPicturesId(), false, preCount, preCount - pictures.getNum(), pictures.getNum(), new Date()));
                        AutoLogMgr.add(new LogDrawPictures(getUserId(), activityInfo.getActivityId(),  pictures.getPicturesId(), false, preCount, preCount - pictures.getNum(), pictures.getNum()));
                    }
                    int totalCount = blueCount + purpleCount + orangeCount;
                    if (totalCount <= 0) {
                        return;
                    }
                    String activityName = ActivityMgr.getActivityName(activityInfo, player.getLanguage());
                    String mailTitle = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.DRAW_PICTURES_ACTIVITY_PICTURES_AUTO_CONSUME_TITLE,
                            player.getLanguage()), activityName);
                    String mailContent = StringUtils.format(MultipleLanguageMgr.getContent(MailManager.DRAW_PICTURES_ACTIVITY_PICTURES_AUTO_CONSUME_CONTENT,
                            player.getLanguage()), activityName, blueName, blueCount, purpleName, purpleCount, orangeName, orangeCount, goodsName);
//                    player.getModule(CurrencyModule.class).addCurrency(new Property(DrawPicturesActivityMgr.getActivityScoreId(activityInfo), BigInteger.valueOf(totalIntegral)),
//                            eLogMoneyType.Activity, eLogMoneyType.DrawPictureReward);
                    String rewardStr = DrawPicturesActivityMgr.getActivityScoreId(activityInfo)  + "=" + totalIntegral;
                    MailManager.sendMailOnLoad(player, eMailType.SYSTEM.getValue(), rewardStr, mailContent, mailTitle);
                }
            }
        }
    }

    private void syncUserDataList() {
        List<Integer> activityIdList = NormalActivityMgr.getOpenActivityIdList(eActivityType.DrawPicturesActivity.getValue());
        if (activityIdList.size() > 0) {
            DrawPicturesProto.DrawPicturesUserActivityDataSyncMsg.Builder syncMsg = DrawPicturesProto.DrawPicturesUserActivityDataSyncMsg.newBuilder();
            for (Integer activityId : activityIdList) {
                UserDrawPicturesActivityData userActivityData = getUserActivityData(activityId);
                Map<Integer, UserPictures> picturesMap = userPicturesMap.get(activityId);
                Map<Integer, UserPicturesComb> combMap = userPicturesCombMap.get(activityId);
                syncMsg.addUserActivityData(DrawPicturesActivityPb.parseUserDataTemp(userActivityData, picturesMap, combMap));
            }
            player.sendPacket(ClientProtocol.U_ACTIVITY_DRAW_PICTURES_USER_DATA_SYNC, syncMsg);
        }
    }

    public UserDrawPicturesActivityData getUserActivityData(int activityId) {
        UserDrawPicturesActivityData data = userDrawPicturesActivityDataMap.get(activityId);
        if (data == null) {
            synchronized (userDrawPicturesActivityDataMap) {
                //先清空上一次活动遗留的活动积分
                //策划又不清了
                //player.getModule(BagModule.class).clearBagItem(DrawPicturesActivityMgr.getActivityScoreId(NormalActivityMgr.getActivityInfo(activityId)), eLogMoneyType.DrawPictureClearIntegral);
                data = userDrawPicturesActivityDataMap.get(activityId);
                if (data == null) {
                    data = new UserDrawPicturesActivityData();
                    data.setActivityId(activityId);
                    data.setUserId(getUserId());
                    data.setCurrentPicturesId(0);
                    data.setInsertOption();
                    userDrawPicturesActivityDataMap.put(activityId, data);
                }
            }
        }
        return data;
    }

    /**
     * 打开年画
     * @param activityId
     * @return
     */
    public DrawPicturesResult openPictures(int activityId) {
        DrawPicturesResult result = new DrawPicturesResult();
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (!checkActivity(activityInfo, result)) {
            result.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return result;
        }
        UserDrawPicturesActivityData userActivityData = getUserActivityData(activityId);
        if (userActivityData.getCurrentPicturesId() != 0) {
            result.setOpenPicturesId(userActivityData.getCurrentPicturesId());
            return result;
        }
        //随机年画id
        int randomPicturesId = DrawPicturesActivityMgr.randomPictures(activityId);
        userActivityData.setCurrentPicturesId(randomPicturesId);
        userActivityData.setLastUpdateTime(System.currentTimeMillis());
        result.setOpenPicturesId(userActivityData.getCurrentPicturesId());
        syncUserDataList();
        return result;
    }

    private boolean checkActivity(ActivityInfo activityInfo, DrawPicturesResult result) {
        if (activityInfo == null || activityInfo.getType() != eActivityType.DrawPicturesActivity.getValue()) {
            result.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return false;
        }
        if (!ActivityMgr.activityInTime(activityInfo)) {
            result.setRet(GameErrorCode.E_ACTIVITY_OVER_TIME);
            return false;
        }
        return true;
    }

    /**
     * 绘制年画
     *
     * @param activityId
     * @param type
     * @return
     */
    public DrawPicturesResult draw(int activityId, int type) {
        int count = type == 2 ? 9 : 1;
        DrawPicturesResult result = new DrawPicturesResult();
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (!checkActivity(activityInfo, result)) {
            result.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return result;
        }

        UserDrawPicturesActivityData userActivityData = getUserActivityData(activityId);
        if (userActivityData.getCurrentPicturesId() == 0) {
            result.setRet(GameErrorCode.E_ACTIVITY_DRAW_PICTURES_NO_OPEN_PIC);
            return result;
        }
        PicturesWeight pictures = DrawPicturesActivityMgr.getPictureWeightMap(activityId).get(userActivityData.getCurrentPicturesId());
        if (pictures == null) {
            result.setRet(GameErrorCode.E_ACTIVITY_DRAW_PICTURES_PIC_NO_EXIST);
            return result;
        }
        //扣除消耗道具
        if (!player.getModule(CurrencyModule.class).removeCurrency(new Property(DrawPicturesActivityMgr.getActivityConsumeId(activityInfo), BigInteger.valueOf(count)),
                eLogMoneyType.Activity, eLogMoneyType.DrawPicturesUseGoods)) {
            result.setRet(GameErrorCode.E_ACTIVITY_TREASURE_GOODS_NO_ENOUGH);
            return result;
        }

        //绘画完成获得年画
        addPictures(activityId, pictures.getId());
        result.getDrawPicturesIdList().add(pictures.getId());
        long addIntegral = pictures.getIntegral();
        if (type == 2) {
            //十连绘制
            for (int i = 0; i < 9; i++) {
                int picturesId = DrawPicturesActivityMgr.randomPictures(activityId);
                PicturesWeight nextPicture = DrawPicturesActivityMgr.getPictureWeightMap(activityId).get(picturesId);
                addPictures(activityId, nextPicture.getId());
                addIntegral += nextPicture.getIntegral();
                result.getDrawPicturesIdList().add(nextPicture.getId());
            }
        }
        userActivityData.setIntegral(userActivityData.getIntegral() + addIntegral);
        result.setAddIntegral((int) addIntegral);
        player.getModule(CurrencyModule.class).addCurrency(new Property(DrawPicturesActivityMgr.getActivityScoreId(activityInfo), BigInteger.valueOf(addIntegral)),
                eLogMoneyType.Activity, eLogMoneyType.DrawPictureReward);
        player.notifyListener(eGamePlayerEventType.DrawPicturesIntegralRank.getValue(), userActivityData.getIntegral());
        player.notifyListener(eGamePlayerEventType.DrawPicturesIntegralCrossRank.getValue(), userActivityData.getIntegral());
        //重置年画
        userActivityData.setCurrentPicturesId(DrawPicturesActivityMgr.randomPictures(activityId));
        userActivityData.setLastUpdateTime(System.currentTimeMillis());
        syncUserDataList();
        return result;
    }

    /**
     * 增加年画
     * @param activityId
     * @param picturesId
     */
    public void addPictures(int activityId, int picturesId) {
        synchronized (userPicturesMap) {
            if (!userPicturesMap.containsKey(activityId)) {
                userPicturesMap.put(activityId, new ConcurrentHashMap<>());
            }
            if (!userPicturesMap.get(activityId).containsKey(picturesId)) {
                UserPictures userPictures = new UserPictures();
                userPictures.setActivityId(activityId);
                userPictures.setUserId(getUserId());
                userPictures.setPicturesId(picturesId);
                userPictures.setNum(0);
                userPictures.setInsertOption();
                userPicturesMap.get(activityId).put(picturesId, userPictures);
            }
            int preCount = userPicturesMap.get(activityId).get(picturesId).getNum();
            userPicturesMap.get(activityId).get(picturesId).
                    setNum(userPicturesMap.get(activityId).get(picturesId).getNum() + 1);
            int curCount = userPicturesMap.get(activityId).get(picturesId).getNum();
//            LogMgr.addLogDrawPictures(new LogDrawPictures(getUserId(), activityId, picturesId, true, preCount,
//                    curCount - preCount, curCount, new Date()));
            AutoLogMgr.add(new LogDrawPictures(getUserId(), activityId, picturesId, true, preCount,
                    curCount - preCount, curCount));
        }
    }

    /**
     * 祈福
     * @param activityId
     * @param combId
     * @return
     */
    public DrawPicturesResult pray(int activityId, int combId) {
        DrawPicturesResult result = new DrawPicturesResult();
        Map<Integer, PicturesComb> picturesCombMap = DrawPicturesActivityMgr.getPicturesCombMap(activityId);
        PicturesComb picturesComb = picturesCombMap.get(combId);
        if (picturesComb == null) {
            result.setRet(GameErrorCode.E_ACTIVITY_DRAW_PICTURES_COMB_NO_EXIST);
            return result;
        }
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);

        if (activityInfo == null || activityInfo.getType() != eActivityType.DrawPicturesActivity.getValue()) {
            result.setRet(GameErrorCode.E_ACTIVITY_NO_FOUND);
            return result;
        }
        UserDrawPicturesActivityData userActivityData = getUserActivityData(activityId);
        //是否达到上限
        int limit = picturesComb.getLimit();
        if (userPicturesCombMap.containsKey(activityId)) {
            if (userPicturesCombMap.get(activityId).containsKey(combId)) {
                if (userPicturesCombMap.get(activityId).get(combId).getTimes() >= limit) {
                    result.setRet(GameErrorCode.E_ACTIVITY_DRAW_PICTURES_COMB_PRAY_TIMES_LIMIT);
                    return result;
                }
            }
        }
        Property prayCost = new Property();
        for (String cost : picturesComb.getElement().split("\\|")) {
            prayCost.addProperty(PropertyHelper.parseStringToProperty(cost));
        }
        if (!removePicture(activityId, prayCost)) {
            result.setRet(GameErrorCode.E_ACTIVITY_DRAW_PICTURES_COMB_UNFINISH);
            return result;
        }
        //祈福奖励
        Property prayReward = PropertyHelper.parseStringToProperty(picturesComb.getRewards());
        result.setReward(picturesComb.getRewards());
        player.getModule(CurrencyModule.class).addCurrency(prayReward, eLogMoneyType.Activity, eLogMoneyType.DrawPicturePrayReward);
        //增加积分
        userActivityData.setIntegral(userActivityData.getIntegral() + picturesComb.getIntegral());
        player.getModule(CurrencyModule.class).addCurrency(new Property(DrawPicturesActivityMgr.getActivityScoreId(activityInfo), BigInteger.valueOf(picturesComb.getIntegral())), eLogMoneyType.Activity, eLogMoneyType.DrawPicturePrayReward);
        result.setAddIntegral(picturesComb.getIntegral());
        player.notifyListener(eGamePlayerEventType.DrawPicturesIntegralRank.getValue(), userActivityData.getIntegral());
        player.notifyListener(eGamePlayerEventType.DrawPicturesIntegralCrossRank.getValue(), userActivityData.getIntegral());
        //祈福任务
        player.notifyListener(eGamePlayerEventType.DrawPicturesCombPrayTimes.getValue(), new DrawPicturesActivityCombArgs(combId, 1));
        //添加祈福记录
        addPicturesComb(activityId, combId);
        syncUserDataList();
        Property totalReward = new Property();
        totalReward.addProperty(prayReward);
        totalReward.addProperty(new Property(DrawPicturesActivityMgr.getActivityScoreId(activityInfo), BigInteger.valueOf(picturesComb.getIntegral())));

        //log日志
//        LogMgr.addLogDrawPicturesPray(getUserId(), activityId, combId, PropertyHelper.parsePropertyToString(prayCost), PropertyHelper.parsePropertyToString(totalReward), System.currentTimeMillis());

        AutoLogMgr.add(new LogDrawPicturesPray(getUserId(), activityId, combId, PropertyHelper.parsePropertyToString(prayCost), PropertyHelper.parsePropertyToString(totalReward)));
        return result;
    }

    private void addPicturesComb(int activityId, int combId) {
        synchronized (userPicturesCombMap) {
            if (!userPicturesCombMap.containsKey(activityId)) {
                userPicturesCombMap.put(activityId, new ConcurrentHashMap<>());
            }
            if (!userPicturesCombMap.get(activityId).containsKey(combId)) {
                UserPicturesComb userPicturesComb = new UserPicturesComb();
                userPicturesComb.setActivityId(activityId);
                userPicturesComb.setCombId(combId);
                userPicturesComb.setUserId(getUserId());
                userPicturesComb.setTimes(0);
                userPicturesComb.setInsertOption();
                userPicturesCombMap.get(activityId).put(combId, userPicturesComb);
            }
            userPicturesCombMap.get(activityId).get(combId).
                    setTimes(userPicturesCombMap.get(activityId).get(combId).getTimes() + 1);
        }
    }

    /**
     * 消耗年画
     * @param activityId
     * @param prayCost
     * @return
     */
    private boolean removePicture(int activityId, Property prayCost) {
        synchronized (userPicturesMap) {
            if (!userPicturesMap.containsKey(activityId)) {
                return false;
            }
            Map<Integer, UserPictures> picturesMap = userPicturesMap.get(activityId);
            for (Map.Entry<Integer, BigInteger> entry : prayCost.getGoods().entrySet()) {
                if (!picturesMap.containsKey(entry.getKey())) {
                    return false;
                }
                UserPictures userPictures = picturesMap.get(entry.getKey());
                if (userPictures.getNum() < entry.getValue().intValue()) {
                    return false;
                }
            }
            for (Map.Entry<Integer, BigInteger> entry : prayCost.getGoods().entrySet()) {
                UserPictures userPictures = picturesMap.get(entry.getKey());
                int preCount = userPictures.getNum();
                userPictures.setNum(userPictures.getNum() - entry.getValue().intValue());
                int curCount = userPictures.getNum();
//                LogMgr.addLogDrawPictures(new LogDrawPictures(getUserId(), activityId, userPictures.getPicturesId(), false, preCount, preCount - curCount, curCount));
                AutoLogMgr.add(new LogDrawPictures(getUserId(), activityId, userPictures.getPicturesId(), false, preCount, preCount - curCount, curCount));
            }
            return true;
        }
    }


    @Override
    public boolean afterLoadData() {
        return true;
    }

    @Override
    public boolean saveData() {
        for (UserDrawPicturesActivityData data : userDrawPicturesActivityDataMap.values()) {
            if (data.isInsertOption()) {
                UserDrawPicturesBusiness.insertDrawPicturesUserActivityData(data);
            } else if (data.isUpdateOption()) {
                UserDrawPicturesBusiness.updateDrawPicturesUserActivityData(data);
            }
        }

        for (Map<Integer, UserPictures> dataMap : userPicturesMap.values()) {
            for (UserPictures data : dataMap.values()) {
                if (data.isInsertOption()) {
                    UserDrawPicturesBusiness.insertDrawPicturesUserPicturesData(data);
                } else if (data.isUpdateOption()) {
                    UserDrawPicturesBusiness.updateDrawPicturesUserPicturesData(data);
                }
            }
        }

        for (Map<Integer, UserPicturesComb> dataMap : userPicturesCombMap.values()) {
            for (UserPicturesComb data : dataMap.values()) {
                if (data.isInsertOption()) {
                    UserDrawPicturesBusiness.insertDrawPicturesUserPicturesCombData(data);
                } else if (data.isUpdateOption()) {
                    UserDrawPicturesBusiness.updateDrawPicturesUserPicturesCombData(data);
                }
            }
        }
        return true;
    }

    @Override
    public void afterLogin() {
        syncActivity();
    }
}
